package com.ai.bitcoin.init;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class ThreadPoolService implements InitializingBean,DisposableBean {

	private ExecutorService htmlFilePool;

	private ExecutorService snapShotPool;

	private ExecutorService wxTemplatePool;

	@Override
	public void destroy() throws Exception {
		htmlFilePool.shutdownNow();
		snapShotPool.shutdownNow();
		wxTemplatePool.shutdownNow();
		try {
			//给线程shutdown的时间
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void afterPropertiesSet() throws Exception {

		htmlFilePool = Executors.newFixedThreadPool(20);
		snapShotPool = Executors.newFixedThreadPool(2);
		wxTemplatePool = Executors.newFixedThreadPool(20);

	}

	public ExecutorService getHtmlFilePool() {
		return htmlFilePool;
	}

	public ExecutorService getSnapShotPool() {
		return snapShotPool;
	}

	public ExecutorService getWxTemplatePool() {
		return wxTemplatePool;
	}
}